VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ScrollBarDriver"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
DefLng H

Private m_wndprcNext As Long
Private hm_hWnd
Private m_CallBack As CallBack
Private m_VScroll As ScrollBar
Private m_HScroll As ScrollBar
Private m_MinMaxInfo As MINMAXINFO

Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal LParam As Long) As Long
    Select Case uMsg
        Case WM_VSCROLL
            m_VScroll.Change wParam
        Case WM_HSCROLL
            m_HScroll.Change wParam
        Case WM_GETMINMAXINFO
            If CallWindowProc(m_wndprcNext, hWnd, uMsg, wParam, LParam) Then
                CopyMemory m_MinMaxInfo, ByVal LParam, Len(m_MinMaxInfo)
                With m_MinMaxInfo
                    With .ptMinTrackSize
                        .X = 380
                        .Y = 350
                    End With
                End With
                CopyMemory ByVal LParam, m_MinMaxInfo, Len(m_MinMaxInfo)
                WindowProc = 1
                Exit Function
            End If
    End Select
    WindowProc = CallWindowProc(m_wndprcNext, hWnd, uMsg, wParam, LParam)
End Function

Public Sub SubClass(ByVal hWnd As Long)
    UnsubClass
    m_wndprcNext = SetWindowLong(hWnd, GWL_WNDPROC, m_CallBack.ProcAddress)
    If m_wndprcNext Then
        m_CallBack.DebugProc = m_wndprcNext
        hm_hWnd = hWnd
        Set m_VScroll = New ScrollBar
        With m_VScroll
            .SB_TYPE = SB_VERT
            .hWnd = hm_hWnd
        End With
        Set m_HScroll = New ScrollBar
        With m_HScroll
            .SB_TYPE = SB_HORZ
            .hWnd = hm_hWnd
        End With
    End If
End Sub

Public Sub UnsubClass()
    If m_wndprcNext Then
        SetWindowLong hm_hWnd, GWL_WNDPROC, m_wndprcNext
        m_wndprcNext = 0
        m_CallBack.DebugProc = m_wndprcNext
        hm_hWnd = 0
        Set m_VScroll = Nothing
        Set m_HScroll = Nothing
    End If
End Sub

Public Property Set VScroll(ScrollBar As ScrollBar)
    Set m_VScroll = ScrollBar
End Property

Public Property Get VScroll() As ScrollBar
    If m_VScroll Is Nothing Then
        Set m_VScroll = New ScrollBar
        With m_VScroll
            .SB_TYPE = SB_VERT
            .hWnd = hm_hWnd
        End With
    End If
    Set VScroll = m_VScroll
End Property

Public Property Set HScroll(ScrollBar As ScrollBar)
    Set m_HScroll = ScrollBar
End Property

Public Property Get HScroll() As ScrollBar
    If m_HScroll Is Nothing Then
        Set m_HScroll = New ScrollBar
        With m_HScroll
            .SB_TYPE = SB_HORZ
            .hWnd = hm_hWnd
        End With
    End If
    Set HScroll = m_HScroll
End Property


Private Sub Class_Initialize()
    Set m_CallBack = NewCallBack(CBType_WNDPROC, Me, True)
End Sub
